package demo1;
import java.util.Random;
import java.util.Scanner;
public class GuessNumberGame {
    public static void main(String[] args) {
        Random random = new Random();
        int secretNumber = random.nextInt(100) + 1;
        Scanner scanner = new Scanner(System.in);
        int guess;
        System.out.println("=== 猜数字游戏 ===");
        System.out.println("我已经想了一个1-100之间的数字");
        while (true) {
            System.out.print("请输入你猜的数字: ");
            guess = scanner.nextInt();
            if (guess == secretNumber) {
                System.out.println("恭喜你，猜对了！");
                break; // 猜对就退出循环
            } else if (guess < secretNumber) {
                System.out.println("太小了，再试试！");
            } else {
                System.out.println("太大了，再试试！");
            }
        }
        scanner.close();
    }
    }

